//
//  TempCacuExt.swift
//  ANOA
//
//  Created by 邱仙凯 on 2023/7/12.
//  Copyright © 2023 zwb. All rights reserved.
//

import UIKit


extension ConfigMenuForm {
 
   // 跳转地图
    func go2MapVC(onexx:TemplateModel,indexPath:IndexPath?) {
        let hasCoo = onexx.grmmarArr.filter{ $0.contains(GrammarType.getCoordinate.rawValue) }
        guard  hasCoo.count > 0 else {
            KSToast("未配置经纬度回填，getCoordinate")
            return
        }
        var arrrr = getKeyPara(hasCoo.first!)
        var brrrr = arrrr
        brrrr.remove(at: 0)
        guard  brrrr.count == 1 else {
            KSToast("getCoordinate回填有误")
            return
        }
        let coorFillBack = brrrr.first!.components(separatedBy: ",")
        var lonDicKey = ""
        var latDicKey = ""
        var addrDicKey = ""
        for item in coorFillBack {
            let pre = item.preChar(char: ":").unwrap
            let suf = item.sufChar(char: ":").unwrap
            if pre == "Longitude" {
                lonDicKey = suf
            }
            if pre == "Latitude" {
                latDicKey = suf
            }
            if pre == "Address" {
                addrDicKey = suf
            }
        }
        
        
        var currData = (0.0,0.0,"")
        if indexPath.isSome {
            let cuDet = self.detHandler[self.cDIndex][indexPath!.section].dic
            currData.0 =  doubleTran(any2Str(cuDet[lonDicKey]))
            currData.1 = doubleTran(any2Str(cuDet[latDicKey]))
            currData.2 =  any2Str(cuDet[addrDicKey])
        } else {
            currData.0 =  doubleTran(any2Str(self.main[lonDicKey]))
            currData.1 = doubleTran(any2Str(self.main[latDicKey]))
            currData.2 =  any2Str(self.main[addrDicKey])
        }
        
        
        TempHelper.shared.go2MapVC(vc:self,currData: currData,onexx: onexx, indexPath: indexPath) { lon, lat, address in
            
            if indexPath.isSome {
                self.detHandler[self.cDIndex][indexPath!.section].dic[lonDicKey] = lon
                self.detHandler[self.cDIndex][indexPath!.section].dic[latDicKey] = lat
                self.detHandler[self.cDIndex][indexPath!.section].dic[addrDicKey] = address
            } else {
                self.main[lonDicKey] = lon
                self.main[latDicKey] = lat
                self.main[addrDicKey] = address
            }
            
            if indexPath.isSome {
                self.reloadDetData(indexPath:indexPath)
                
            } else {
                self.configTempDataSource()
                
                self.continueUrl(onexx: onexx)
            }
        }
        
        
    }
    
}
 
